﻿

//using System;
//using System.Web;
//using Castle.MicroKernel;
//using Castle.MicroKernel.Context;
//using Castle.MicroKernel.Lifestyle;

//namespace Family.Core
//{
//    [Serializable]
//    public class PerWebRequestLifestyleManager : Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleManager 
//    {
//        public PerWebRequestLifestyleManager()
//        {
//            _fallback = new TransientLifestyleManager();
//        }

//        public override object Resolve(CreationContext context)
//        {
//            HttpContext current = HttpContext.Current;
//            if (null == current || current.ApplicationInstance == null)
//            {
//                // fall back to transient behaviour if not in web context 
//                return _fallback.Resolve(context);
//            }
//            else
//            {
//                return base.Resolve(context);
//            }
//        }

//        public override void Dispose()
//        {
//            _fallback.Dispose();
//            base.Dispose();
//        }

//        public override void Init(IComponentActivator componentActivator, IKernel kernel, Castle.Core.ComponentModel model)
//        {
//            base.Init(componentActivator, kernel, model);
//            _fallback.Init(componentActivator, kernel, model);
//        }

//        private TransientLifestyleManager _fallback;
//    }
//}
